#ifndef RTSP_READER_H
#define RTSP_READER_H

#include <iostream>
#include <string>

extern "C" {
/* Include ffmpeg header file */
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>

#include <libavutil/imgutils.h>
}

#include <opencv2/opencv.hpp>
#include <boost/thread.hpp>


class RtspReader{

public:
	RtspReader(std::string url);
	~RtspReader();
	void Play();
	cv::Mat GetFrame();
	cv::Mat GetFrame2();

private:
	std::string url;
	AVFormatContext *ifmt_ctx = NULL;
	AVDictionary* avdic = NULL;
	int video_index = -1;
	AVCodecContext * codec_ctx = NULL;
	AVCodec *codec = NULL;

	uint8_t *buffer = NULL;
	int numBytes = -1;
	AVFrame *rawframe = NULL;
	AVFrame *bgrframe = NULL;
	struct SwsContext *img_cvrt_ctx = NULL;

	cv::Mat curFrame;

	void init();
	void release();
};


#endif // !RTSP_READER_H
